/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package controller.admin;

import com.google.common.collect.BiMap;
import dao.BinhLuanDao;
import dao.SanPhamDao;
import dao.ThanhVienDao;
import javax.faces.context.FacesContext;
import pojo.Binhluan;
import pojo.Sanpham;
import pojo.Thanhvien;

/**
 *
 * @author Alvis
 */
public class Admin_CommentController {

    /** Creates a new instance of Admin_CommentController */
    private Binhluan binhLuanTemp = new Binhluan();
    public Admin_CommentController() {
        binhLuanTemp.setSanpham(new Sanpham());
        binhLuanTemp.setThanhvien(new Thanhvien());
        
    }

    /**
     * @return the binhLuanTemp
     */
    public Binhluan getBinhLuanTemp() {
        return binhLuanTemp;
    }

    /**
     * @param binhLuanTemp the binhLuanTemp to set
     */
    public void setBinhLuanTemp(Binhluan binhLuanTemp) {
        this.binhLuanTemp = binhLuanTemp;
    }
     public String UpdateComment()
    {
        BinhLuanDao binhLuanDAO = new BinhLuanDao();
        ThanhVienDao tvDAO = new ThanhVienDao();
        SanPhamDao spDAO = new SanPhamDao();
        Binhluan value = new Binhluan();
        Thanhvien thanhvien = new Thanhvien();
        thanhvien=tvDAO.getMember(binhLuanTemp.getThanhvien().getUsername());
        Sanpham sanpham = new Sanpham();
        sanpham = spDAO.getProduct(binhLuanTemp.getSanpham().getMasanpham());
        value.setNoidung(binhLuanTemp.getNoidung());
        value.setSanpham(sanpham);
        value.setThanhvien(thanhvien);
        binhLuanDAO.Update(value,binhLuanTemp.getMabinhluan());
        return "indexcomment";
    }
      public String DeleteComment()
    {
        BinhLuanDao binhLuanDAO = new BinhLuanDao();
        
        binhLuanDAO.Delete(binhLuanTemp.getMabinhluan());
        return "indexcomment";
    }
     public String getCommentUpdate() {
        BinhLuanDao binhLuanDAO = new BinhLuanDao();
        setBinhLuanTemp(binhLuanDAO.getComment(Integer.parseInt(FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("txtID").toString())));
        return "updatecomment";

    }
    public String getCommentDelete() {
        BinhLuanDao binhLuanDAO = new BinhLuanDao();
        setBinhLuanTemp(binhLuanDAO.getComment(Integer.parseInt(FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("txtID").toString())));
        return "deletecomment";

    }
    public Binhluan[] getCommentList() {
        Binhluan[] list;
        try {
            BinhLuanDao binhLuanDAO = new BinhLuanDao();
            list = binhLuanDAO.getAllComment();

        } catch (Exception ex) {
            System.out.println(ex.getMessage());
            list = null;
        }
        return list;

    }
}
